<template>
  <div class="c-bg-white c-ph24">
    <div class="c-fs-36 c-fc-sxblack c-textAlign-c c-pt60">{{paperInfo.name}}</div>
    <div class="c-mt40">
      <img class="c-w100" :src="$addXossFilter(paperInfo.avatar, require('../../../assets/defult270.png'))" @error="setDefultImg" />
    </div>
    <div class="c-fs28 c-fc-sxblack c-lh48 c-mt44">{{paperInfo.description}}</div>
    <div class="c-fs28 c-fc-white c-hh80 c-textAlign-c c-flex-row c-flex-center theme-bg c-mt120 c-br10 c-mb20" @click="startTest">开始测试</div>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js"
import defultImg from '@/assets/defult270.png'
export default {
  name: "QuizEntry",
  components: {

  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : 'mb5_default',
      paperMainId: -1,
      topicId: -1,
      paperInfo: {},
      examinationInfo: null
    };
  },
  created() {
    utilJs.appShare(this);
  },
  activated() {
    setDocumentTitle("开始测试");// eslint-disable-line
    this.topicId = this.$route.query.topicId;
    this.paperMainId = this.$route.query.paperMainId;
    let $this = this;
    //获取详情信息
    utilJs.getMethod(global.apiurl + 'exam/paperInfo/' + this.paperMainId, function (res) {
      if (res != null) {
        $this.paperInfo = res;
      }
      //    $this.wechatShare();
    });

    utilJs.getMethod(global.apiurl + 'exam/topicDetail/' + this.topicId, function (res) {
      $this.examinationInfo = res.topicInfo;
      $this.wechatShare();
    })
  },
  deactivated() {
  },
  mounted() { },
  methods: {
    setDefultImg(e) {
      this.paperInfo.avatar = defultImg;
    },
    startTest() {
      let $this = this;
      utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
        paperMainId: this.paperMainId,
        topicId:this.topicId,
        entryProdType:2,
        prodId:this.topicId
      }, res => {
        $this.$routerGo($this, "replace", {
          path: "/homePage/examination/examinationAnswer",
          query: { paperMainId: $this.paperMainId, topicId: $this.topicId, goOnNum: 1 }
        });
      })
    },
    //分享
    wechatShare: function () {
      let title = this.examinationInfo.name;
      let shareImg = this.examinationInfo.avatar || require('../../../assets/examination_defult.png');
      let shareUrl = `${window.location.href.split("#")[0]}#/homePage/examination/examinationDetail?ExaminationNo=${this.topicId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.examinationInfo.shareDesc;//"共包含"+this.examinationInfo.hasPaper+"套考卷";
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { });
    },
    //手机端分享
    appShare: function () {
      let title = this.examinationInfo.name;
      let shareImg = this.examinationInfo.avatar || require('../../../assets/examination_defult.png');
      let shareUrl = `${window.location.href.split("#")[0]}#/homePage/examination/examinationDetail?ExaminationNo=${this.topicId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.examinationInfo.shareDesc;//"共包含"+this.examinationInfo.hasPaper+"套考卷";
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
</style>
